<template>
	<view class="addInspectTabsContent">
		<view class="upper">
			<commonNavBar title="结果记录表"     >
				<template v-slot:right>
					<image src="/static/img/save.png" @tap="saveImage"  style="width: 45rpx;height: 45rpx;"></image>
				</template>
			</commonNavBar>     
			<scroll-view id="content" :scroll-y="true" :style="{height: contentHeight + 'px'}">
				<view id="scrrent-page" class="list"> 
				<view class="title-view">
					<text class="title-text">食品生产日常监督检查结果记录表</text> </view>
					<view class="title-view" :style="{'text-align':'right','padding-right':'5px'}"> <text class="title-text">编号：{{resultCode}}</text> </view>
				 <table class="content-table" celspacing="0" > 
					 <tr>
						 <td class="content-td" width="90rpx">被检查单位名称</td>
						 <td class="content-td" width="300rpx">{{checkData.companyName}}</td>
						 <td class="content-td" width="90rpx">地址</td>
						 <td class="content-td" width="300rpx">{{checkData.address}}</td>
					 </tr>
					 <tr>
						 <td class="content-td" width="90rpx">联系人</td>
						 <td class="content-td" width="300rpx">{{checkData.contact}}</td>
						 <td class="content-td" width="90rpx">联系方式</td>
						 <td class="content-td" width="300rpx">{{checkData.contactPhone}}</td>
					 </tr>
					<tr>
						 <td class="content-td" width="90rpx">许可证编号或备案号</td>
						 <td class="content-td" width="300rpx">{{checkData.license}}</td>
						 <td class="content-td" width="90rpx">检查次数</td>
						 <td class="content-td" width="300rpx">
							<span v-if="serialNum === 99">本年度非计划检查</span>
							<span v-else>本年度第（{{serialNum}}）次检查</span>
						 </td>
					</tr>
					<tr>
						 <td class="content-td" colspan="4"  >
							 <view>检查内容：</view>
							 <view>　　
                 {{checkData.deptName}}&nbsp;检查人员 {{lawEnforcementOfficerOne}}，{{lawEnforcer2Value}} 根据　　
                 《中华人民共和国食品安全法》及其实施条例、《食品生产经营监督检查管理办法》等规定,于{{checkTime}}至.{{checkTime}}。
                 对你单位进行了 √·日常监督检查 &nbsp; &nbsp;□·飞行检查 &nbsp; &nbsp;□·体系检查;
                 本次监督检查依据 √食品生产监督检查要点表 &nbsp; &nbsp;□ 其他:______________________________
                 共检查({{dataObj.contentNum}})项，其中重点项({{dataObj.importantOneCount}})项，一般项({{dataObj.importantZeroCount}})项。
							 </view>
						 </td>
					</tr>
					<tr>
						 <td class="content-td" colspan="4" >
               <view >检查结果：</view>
               <view style="margin-top: 10px;">本次检查发现不符合项(　{{dataObj.importantOneContentSelectZeroOrNegativeCount + dataObj.importantZeroContentSelectZeroOrNegativeCount}})项 其中：</view>
               <view style="margin-top: 10px;">重点项({{dataObj.importantOneContentSelectZeroOrNegativeCount}})项,项目序号分别是 (　{{dataObj.importantOneContentSelectZeroOrNegativeSerialNumbers}} )</view>
               <view style="margin-top: 10px;">一般项(　{{dataObj.importantZeroContentSelectZeroOrNegativeCount}})项,项目序号分别是 (　{{dataObj.importantZeroContentSelectZeroOrNegativeSerialNumbers}}　)</view>
               <!-- <view >处理结果：&nbsp; &nbsp; {{ dataObj.handleResult === '0' ? '通过' : dataObj.handleResult === '1' ? '责令整改' : '调查处理' }}</view> -->
			   <view >处理结果：&nbsp; &nbsp; {{ dataObj.handleResult === '0' ? '通过' : dataObj.handleResult === '1' ? '责令整改' : '调查处理' }} {{ checkTime != null ? `(${checkTime}前整改到位)` : '' }}</view>
               <view  style="margin-top: 10px;"  >说明： {{dataObj.disReason}}</view>
						 </td>
					</tr>
					<tr>
						 <td class="content-td" colspan="2"  >
							<view>检查人员（签名）：<image class="signature-image" :src="sigPic == null ? '/static/img/sing.png' : sigPic" @tap="sign(1)"> </image></view>
							<view>检查人员（签名）：<image class="signature-image" :src="sigPic2 == null ? '/static/img/sing.png' : sigPic2" @tap="sign(2)"> </image></view>
							<view style="text-align: right;"><text> {{formattedDate}}</text> </view>
						 </td>
						 <td class="content-td" colspan="2"   style="padding-top:100px;">
							<view>法定代表人或负责人（签名）：<image class="signature-image" :src="sigPic3 == null ? '/static/img/sing.png' : sigPic3" @tap="sign(3)"> </image>
							</view>
							<view style="text-align: right;margin-top: 10px;"><text> {{formattedDate}}</text></view>
						 </td>
					</tr>
					<tr>
						 <td class="content-td" >备注</td>
						 <td class="content-td" colspan="3"  >
							 被检查单位为食品经营者的填写许可证编号，固定食品制售摊贩、早餐车填写备案证明编号
							 ，其他业态类型的填写社会信用代码；日常监督检查结果为不符合，如发现涉及食品安全违法行为的，应依法进行立案调查处理；
							 如涉及移送情形的，应依法移送相关有权处理部门。结果处理应使用规范的法律文书；文中各类检查要点表与其风险分级动态评级表为同一张表。
						 </td>
					</tr> 
					<tr>
						<td class="content-td" colspan="4" style="text-align: center;">
							 郑重提示:食品生产者应按相关部门要求，做好安全生产工作，防止生产安全事故，保障人员的生命和财产安全。
						</td>
					</tr>
				 </table>
			</view>
			</scroll-view>
		</view> 
		<screenshot ref="screenshot" :screenId="'scrrent-page'" @renderFinish="getScreenImg"></screenshot>
	</view>
</template>

<script>
	const currentDate = new Date();
	const year = currentDate.getFullYear();
	const month = String(currentDate.getMonth() + 1).padStart(2, '0');
	const day = String(currentDate.getDate()).padStart(2, '0');
	const formattedDate = `${year}年${month}月${day}日`;
	import longscreen from '@/components/screenShot.vue' 
	import commonNavBar from '@/components/CommonNavBar.vue';
	
	export default {
		components:{
			commonNavBar,
			'screenshot': longscreen 
		},
		data() {
			return {
				checkData: {
					standardList: []
				},
				resultCode:"",
				sigPic:null,
				sigPic2:null,
				sigPic3:null,
				checkId:null,
				contentHeight:0,
				formattedDate:formattedDate,
        lawEnforcer2Value: null,
        lawEnforcementOfficerOne: null,
				numId: null,
				checkTime: null,
				serialNum: null,
				dataObj: null
			}
		},
		filters: {
			selectionFilter(value) {

				if (value == '1') {
					return '是'
				} else if (value == '2') {
					return '否'
				} else if (value == '3') {
					return '合理缺项'
				} else {
					return '';
				}

			},
			dateFilter(value){
				if (value == undefined || value == 'undefined') {
					return ''
				} else {
					const  valueArr =  value.split("-");
					return valueArr[0]+'年'+valueArr[1]+'月'+valueArr[2]+'日'
				}
			}, 
			processResultFilter(value){
				if (value == undefined || value == 'undefined') {
					return ''
				} else {
					 //1通过检查，2责令整改，3调查处理
					 if(value == '1'){
						 return '通过检查'; 
					 } else if(value == '2'){
						 return '责令整改'; 
					 }  else if(value == '3'){
						 return '调查处理'; 
					 } 
				}
			}
		},
		onLoad(options) {
			this.checkId = options.id 
			this.numId = options.numId
			this.lawEnforcementOfficerOne = options.lawEnforcementOfficerOne
			this.lawEnforcer2Value = options.lawEnforcer2Value
			this.checkTime = options.checkTime
			this.serialNum = options.serialNum
			this.dataObj = options.dataObj
		},
		onReady() {
			const that = this;
			this.initLoadData();
			uni.createSelectorQuery().in(this).select("#content").fields({
				rect: true
			}, function(res) {
				that.contentHeight = uni.getSystemInfoSync().windowHeight - res.top
			}).exec();
			that.dataObj = JSON.parse(decodeURIComponent(this.dataObj));
		},
		methods: {
			goBack() {
				uni.navigateBack();
			},
			async initLoadData() {
				//加载页面所需要数据	
				uni.showLoading({
					title:'获取数据中',
					mask: true
				})
				const res = await uni.$api.productionInspectGetCompanyInfo({
					companyId: this.checkId 
				})
				
				if (res.data.code == '1') {
					uni.hideLoading();
					uni.showToast({
						title: '获取信息失败',
						icon: 'error'
					})
					return;
				}
				console.log("获取数据完成")
				this.checkData = res.data.data
				const res2 = await uni.$api.productionInspectGetResultTableInfo({ 
					checkId: this.numId == 'undefined' ? null : this.numId,
					companyId: this.checkId 
				})
				this.resultCode = res2.data.data
				
				if (res2.data.code == '1') {
					uni.hideLoading();
					uni.showToast({
						title: '获取检查结果记录表编号失败',
						icon: 'error'
					})
					return;
				}
				uni.hideLoading();
			},
			saveImage() {
				this.$refs.screenshot.startScreen();
			},
			getScreenImg(ret) {
				const that = this;
				//根据传输过来的id 和选中的图片传到后台直接保存 
				uni.showLoading({
					title: '正在生成' ,
					mask: true
				})
				uni.uploadFile({
					url: uni.$baseUrl + 'pro/ratingScore/uploadImg',
					filePath: ret.posterPath,
					name: 'file',
					success: (uploadFileRes) => {
						const obj = JSON.parse(uploadFileRes.data);
						uni.hideLoading();
						if (obj.code == '0') {
							// that.$set(that.rectificationSituationDataList[index]
							// 	.contentList[dataIndex], "filePath", obj.data
							// 	.filePath);
							const eventChannel = that.getOpenerEventChannel();
							eventChannel.emit('yaodianbiao', obj.data.filePath);
							uni.navigateBack();
							uni.showModal({
								content: '保存成功',
								title: '提示',
								showCancel: false
							})
						} else {
							uni.showToast({
								icon: 'success',
								title: '存储失败'
							})
						}
					}
				});
				// const uploadTask = uni.uploadFile({
				// 	url: '/dailyInspect/uploadResultRecord', //仅为示例，非真实的接口地址
				// 	filePath: ret.posterPath,
				// 	name: "imgFile",
				// 	timeout: '10000', //超时时间10秒
				// 	formData: {
				// 		"checkId": that.checkId,
				// 		"type":'2'
				// 	},
				// 	dataType: 'json',
				// 	success: (upRes) => {
				// 		uni.showToast({
				// 			title: '生成完成',
				// 			icon: 'success'
				// 		});
				// 		console.log(upRes.data)
				// 		const result = JSON.parse(upRes.data);
				// 		if( result.code  == '1'){
				// 			uni.showModal({
				// 				content: '保存失败,请重新尝试',
				// 				showCancel: false
				// 			})
				// 		}
				// 		console.log( result.data)
				// 		const eventChannel = that.getOpenerEventChannel();
				// 		eventChannel.emit('yaodianbiao', result.data);
				// 		uni.navigateBack();
				// 	},
				// 	fail(err) {
				// 		uni.showModal({
				// 			content: '保存失败,请重新尝试',
				// 			showCancel: false
				// 		})
				// 	},
				// 	complete() {
				// 		uni.hideLoading()
				// 	}
				// });
			},
			sign(type){ 
				const that =this;
				//签名
				 uni.navigateTo({
				 	url:'/pages/signature/signature',
					events:{
						updateSign(data){ 
							if(type == 1){
								that.sigPic = data;
							} else if(type == 2){
								that.sigPic2 = data;
							}  else if(type == 3){
								that.sigPic3 = data;
							} 
						}
					}
				 })
			}
		}
	}
</script>

<style lang="scss">
	.addInspectTabsContent {
		background: #F9F9F9;
		// height: calc(100vh - 195rpx);
		height: 100vh;
		padding: 14px;
		.upper {
			position: fixed;
			z-index: 1;
			top: 0;
			left: 0;
			width: 100%;

			.title {
				background: url('../../static/img/inspectBg.png');
				background-size: cover;
				width: 100%;
				height: 115rpx;
				line-height: 115rpx;
				position: relative;
				display: flex;
				justify-content: center;
				color: #ffffff;

				.arrow {
					position: absolute;
					left: 33rpx;
					top: 50%;
					transform: translate(0%, -50%);
					width: 100rpx;
					height: 100rpx;

					&::before {
						display: block;
						content: "";
						position: absolute;
						top: 50%;
						left: 0%;
						width: 20rpx;
						height: 20rpx;
						border-left: 1px solid #fff;
						border-top: 1px solid #fff;
						transform: translate(0%, -50%) rotate(-45deg);
					}
				}

				text {
					font-size: 30rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					letter-spacing: 1px;
				}

			}
		}
	}

	.intelligence {
		position: absolute;
		right: 30rpx;
		top: 35rpx;
		display: flex;
		align-items: center;
		justify-content: center;

	}
	.list{
		padding-top: 20px;
		padding-bottom: 180px;
		overflow-y: auto;
	}
	.title-view{
		width: 750rpx;
		text-align: center;
	}
	.title-text{
		font-size: 20rpx;
		color: black;
		font-weight: 700;
		
	}
	.content-table{
		width: 750rpx;
		
		
	}
	.content-td {
		border: 1px solid #8a8a8a;
		padding: 10px;
	}
	.signature-image{
		width: 100px;
		height: 100px;
	}
</style>